/**
 * Created by dell on 2017/4/8.
 */
var express=require('express');
var app=express();
const bodyParser = require('body-parser');
app.use(bodyParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const router=require('./router');
const mongoose=require('mongoose');
const config=require('./config/db');

const db=mongoose.connect(config.mongodb);
db.connection.on("error", function (error) {
  console.log("数据库连接失败：" + error);
});

db.connection.on("open", function () {
  console.log("数据库连接成功");
})

db.connection.on('disconnected', function () {
  console.log('数据库连接断开');
})
mongoose.Promise = global.Promise;
app.use('/api',router)

app.listen(2121,function(){
  console.log('express run success...')
})
